﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp0
{
    public partial class shang_dan_3overUserControl : UserControl
    {
        public shang_dan_3overUserControl()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }
        private void Table_over()  //已完成
        {
            dataGridView3.Rows.Clear();
            string sql1 = "select o.Oid,c.Cid,c.Cname,m.Mid,m.Mname,m.Munit,m.Mnorm,o.Onum,m.Mprince from OrderM o ,Customer c, Merchandise m where o.Mid = m.Mid and o.Cid = c.Cid and o.Ostate = '已完成'";
            Dao dao = new Dao();
            IDataReader dr1 = dao.read(sql1);
            while (dr1.Read())
            {
                string a, b, c ,  d, j,f , g,h,i;
                a = dr1["Oid"].ToString();
                b = dr1["Cid"].ToString();
                c = dr1["Cname"].ToString();

                d = dr1["Mid"].ToString();
                j= dr1["Mname"].ToString();
                f = dr1["Munit"].ToString();
                g = dr1["Mnorm"].ToString();
                h = dr1["Onum"].ToString();
                i = dr1["Mprince"].ToString();
           
                string[] str = { a, b, c, d, j, f, g, h, i};
                dataGridView3.Rows.Add(str);
            }
            dr1.Close();//关闭连接 
        }

        private void shang_dan_3overUserControl_Load(object sender, EventArgs e)
        {
            Table_over();
        }

        private void button1_Click(object sender, EventArgs e)
        {//按订单编号
            dataGridView3.Rows.Clear();
            string sql1 = $"select o.Oid,c.Cid,c.Cname,m.Mid,m.Mname,m.Munit,m.Mnorm,o.Onum,m.Mprince from OrderM o ,Customer c, Merchandise m where o.Mid = m.Mid and o.Cid = c.Cid and o.Ostate = '已完成'and o.Oid like '{textBox1.Text}%'";
            Dao dao = new Dao();
            IDataReader dr1 = dao.read(sql1);
            while (dr1.Read())
            {
                string a, b, c, d, j, f, g, h, i;
                a = dr1["Oid"].ToString();
                b = dr1["Cid"].ToString();
                c = dr1["Cname"].ToString();

                d = dr1["Mid"].ToString();
                j = dr1["Mname"].ToString();
                f = dr1["Munit"].ToString();
                g = dr1["Mnorm"].ToString();
                h = dr1["Onum"].ToString();
                i = dr1["Mprince"].ToString();

                string[] str = { a, b, c, d, j, f, g, h, i };
                dataGridView3.Rows.Add(str);
            }
            dr1.Close();//关闭连接 
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Table_over();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {//商品名称查询，text2
            dataGridView3.Rows.Clear();
            string sql1 = $"select o.Oid,c.Cid,c.Cname,m.Mid,m.Mname,m.Munit,m.Mnorm,o.Onum,m.Mprince from OrderM o ,Customer c, Merchandise m where o.Mid = m.Mid and o.Cid = c.Cid and o.Ostate = '已完成' and m.Mname like '%{textBox2.Text}%'";
            Dao dao = new Dao();
            IDataReader dr1 = dao.read(sql1);
            while (dr1.Read())
            {
                string a, b, c, d, j, f, g, h, i;
                a = dr1["Oid"].ToString();
                b = dr1["Cid"].ToString();
                c = dr1["Cname"].ToString();

                d = dr1["Mid"].ToString();
                j = dr1["Mname"].ToString();
                f = dr1["Munit"].ToString();
                g = dr1["Mnorm"].ToString();
                h = dr1["Onum"].ToString();
                i = dr1["Mprince"].ToString();

                string[] str = { a, b, c, d, j, f, g, h, i };
                dataGridView3.Rows.Add(str);
            }
            dr1.Close();//关闭连接 
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {//客户编号查询，text4
            dataGridView3.Rows.Clear();
            string sql1 = $"select o.Oid,c.Cid,c.Cname,m.Mid,m.Mname,m.Munit,m.Mnorm,o.Onum,m.Mprince from OrderM o ,Customer c, Merchandise m where o.Mid = m.Mid and o.Cid = c.Cid and o.Ostate = '已完成'and c.Cid='{textBox4.Text}'";
            Dao dao = new Dao();
            IDataReader dr1 = dao.read(sql1);
            while (dr1.Read())
            {
                string a, b, c, d, j, f, g, h, i;
                a = dr1["Oid"].ToString();
                b = dr1["Cid"].ToString();
                c = dr1["Cname"].ToString();

                d = dr1["Mid"].ToString();
                j = dr1["Mname"].ToString();
                f = dr1["Munit"].ToString();
                g = dr1["Mnorm"].ToString();
                h = dr1["Onum"].ToString();
                i = dr1["Mprince"].ToString();

                string[] str = { a, b, c, d, j, f, g, h, i };
                dataGridView3.Rows.Add(str);
            }
            dr1.Close();//关闭连接 
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {//客户名称查询，text3
            dataGridView3.Rows.Clear();
            string sql1 = $"select o.Oid,c.Cid,c.Cname,m.Mid,m.Mname,m.Munit,m.Mnorm,o.Onum,m.Mprince from OrderM o ,Customer c, Merchandise m where o.Mid = m.Mid and o.Cid = c.Cid and o.Ostate = '已完成'and c.Cname like '%{textBox3.Text}%'";
            Dao dao = new Dao();
            IDataReader dr1 = dao.read(sql1);
            while (dr1.Read())
            {
                string a, b, c, d, j, f, g, h, i;
                a = dr1["Oid"].ToString();
                b = dr1["Cid"].ToString();
                c = dr1["Cname"].ToString();

                d = dr1["Mid"].ToString();
                j = dr1["Mname"].ToString();
                f = dr1["Munit"].ToString();
                g = dr1["Mnorm"].ToString();
                h = dr1["Onum"].ToString();
                i = dr1["Mprince"].ToString();

                string[] str = { a, b, c, d, j, f, g, h, i };
                dataGridView3.Rows.Add(str);
            }
            dr1.Close();//关闭连接 
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }
    }
}
